$(function(){
    var group_edit_box = new Vue({
        el: "#group_edit",
        data: {
            token: '',
            group_name: '',
            description: '',
            group_id: 0,
        },
        mounted: function() {
            this.initialPage();
            this.getGroup();
        },
        watch: {// 数据变化事件

        },
        methods: {
            initialPage: function () {
                this.token = $('#lcm_lingpai').val();
                // 设置弹窗
                toastr.options = {
                    "closeButton": true, // 是否显示关闭按钮
                    "debug": false,       // 是否使用debug模式
                    "positionClass": "toast-top-center",// 弹出窗的位置
                    "showDuration": "100", // 显示的动画时间
                    "hideDuration": "100",// 消失的动画时间
                    "timeOut": "1000",     // 展现时间
                    "extendedTimeOut": "100",// 加长展示时间
                    "showEasing": "swing",    // 显示时的动画缓冲方式
                    "hideEasing": "linear",   // 消失时的动画缓冲方式
                    "showMethod": "fadeIn",   // 显示时的动画方式
                    "hideMethod": "fadeOut"   // 消失时的动画方式
                };
            },
            getGroup: function () {
                $.ajax({
                    method: 'POST',
                    url: '/backend/group/getgrouppost',
                    data: {
                        _token: this.token,
                    },
                    dataType: 'json',
                    success:(res)=>{
                        if (res.code == 200) {
                            group_edit_box.group_name = res['data']['group_name'];
                            group_edit_box.group_id = res['data']['id'];
                            group_edit_box.description = res['data']['description'];
                        }
                    }
                })
            },
            setGroup: function () {
                if (this.group_name == undefined || this.group_name == '') {
                    toastr.error('企业名称不能为空');
                    return false;
                }

                $.ajax({
                    method: 'POST',
                    url: '/backend/group/setgrouppost',
                    data: {
                        _token: this.token,
                        group_id: this.group_id,
                        group_name: this.group_name,
                        description: this.description,
                    },
                    dataType: 'json',
                    success:(res)=>{
                        if (res.code == 200) {
                            var old_group_id = group_edit_box.group_id;
                            group_edit_box.group_id = res['data']['group_id'];
                            group_edit_box.group_name = res['data']['group_name'];
                            toastr.success(res.message);
                            if (old_group_id == 0) {
                                window.location.href = window.location.href;
                            }
                        } else {
                            toastr.error(res.message);
                        }
                    }
                })
            }
        }
    });
});
